﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SimpleData.Infrastructure.Plugins;

namespace SimpleData.Data.Internals
{

	/// <summary>
	/// 
	/// </summary>
	/// <typeparam name="TRepository"></typeparam>
	internal sealed class RepositoryFactory<TRepository>
		where TRepository : IRepository
	{
		private Plug plugins;

		/// <summary>
		/// 
		/// </summary>
		internal RepositoryFactory( Plug plugins )
		{
			this.plugins = plugins;
		}

		/// <summary>
		/// Realiza a criação do repositório <typeparamref name="TRepository"/>
		/// </summary>
		/// <returns></returns>
		public TRepository Create()
		{
			return this.plugins.Create<TRepository>();
		}

		/// <summary>
		/// Cria um novo scope de execução para acessar o repositório <typeparamref name="TRepository"/>
		/// </summary>
		/// <returns></returns>
		public DatabaseScope<TRepository> Scope()
		{
			return new DatabaseScope<TRepository>( this.Create() );
		}
	}
}
